import { getCarsRequest } from "@/apis/cars"
import { makeAutoObservable } from "mobx"
import { makePersistable } from "mobx-persist-store"

export interface carsTypes {
	id: number
	number: string
	picture: string
	username: string
	phone: string
	x: number
	y: number
	storey: number,
	position: string
	pid: number
	uid: number
	type: string
}

export class carsStore {
	cars: carsTypes[] = []
	constructor() {
		makeAutoObservable(this, {}, { autoBind: true })
		makePersistable(this, {
			name: 'carsStore',
			properties: ['cars'],
			storage: window.localStorage,
		})
	}

	setCars(c: carsTypes[]) {
		this.cars = c
	}

	getCars() {
		getCarsRequest().then((res: any) => {
			this.setCars(res.result)
		})
	}
}
